/*
 * Copyright (c) 2009 LastFM.Desktop Anton Pavlik.
 * All Rights Reserved.
 * 
 * You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, 
 * with or without modifications, and in Source or Object form, provided that You meet the following 
 * conditions:
 * 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
 *
 * 2. You must cause any modified files to carry prominent notices stating that You changed the files; 
 * and
 *
 * 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, 
 * patent, trademark, and attribution notices from the Source form of the Work, excluding those notices 
 * that do not pertain to any part of the Derivative Works.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, Licensor provides the Work 
 * (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties 
 * or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. 
 * YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE WORK
 * AND ASSUME ANY RISKS ASSOCIATED WITH YOUR EXERCISE OF PERMISSIONS UNDER THIS LICENSE. 
 */
package org.shake.lastfm.ui.model;

import org.shake.lastfm.model.Track;
import org.shake.lastfm.model.TrackStatus;
import org.shake.lastfm.ui.AbstractGenericTableModel;

public class TracksTableModel extends AbstractGenericTableModel<Track>
{
	private static final long serialVersionUID = -6270903550839430687L;

	private final String[] columns = {".", "Status", "Title/Creator"};
	
	@Override
	public int getColumnCount() {
		return columns.length;
	}

	
	public String getColumnName(int colIdx)
	{
	    return columns[colIdx];
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Track record = getRecord(rowIndex);
		
		switch (columnIndex)
		{
		    case 0:
		        return true;
		    case 1:
		        return record.getStatus();
		    case 2:
		        return record.getTitle() + " / " + record.getCreator();
		}
		
	    return null;
	}
	
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
        return columnIndex == 0;
    }

    @Override
    public void setValueAt(Object value, int rowIndex, int columnIndex)
    {
        if (columnIndex == 0)
        {
            if (value instanceof Boolean)
            {
//                getRecord(rowIndex).setScheduled((Boolean)value);
                fireTableCellUpdated(rowIndex, columnIndex);
            }
        }
    }

    @Override
    public Class<?> getColumnClass(int colIdx)
    {
        switch (colIdx)
        {
            case 0:
                return Boolean.class;
            case 1:
                return TrackStatus.class;
            default:
                return String.class;
                
        }
    }
}
